package cn.edu.hqu.cst.crj.recyclerdemo2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder>{
    private List<String> buttonName;

    public RecyclerAdapter(List<String>buttonName)
    {
        this.buttonName = buttonName;
    }

    public RecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
    {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
        ViewHolder viewHolder = new ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.name.setText(buttonName.get(position));
    }
    class ViewHolder extends RecyclerView.ViewHolder
    {
        TextView name; //按钮名字

        public ViewHolder(@NonNull View itemView)
        {
            super(itemView);
            this.name = itemView.findViewById(R.id.bt_name);
        }

    }
    @Override
    public int getItemCount() {
        return buttonName.size();
    }


}
